package com.csap.framework.oauth2.server.listener;

import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.SaLoginModel;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yangchengfu
 * @dataTime 2021年-07月-30日 14:58:00
 **/
@Slf4j
public class TokenListener implements SaTokenListener {
    @Override
    public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) {
        log("用户登录-loginType:{},loginId:{}", loginType, loginId);
    }

    @Override
    public void doLogout(String loginType, Object loginId, String tokenValue) {
        log("用户退出登录-loginType:{},loginId:{},token value:{}", loginType, loginId, tokenValue);
    }

    @Override
    public void doLogoutByLoginId(String loginType, Object loginId, String tokenValue, String device) {
        log("被踢下线时触发:{},{},{},{}", loginType, loginId, tokenValue, device);
    }

    @Override
    public void doReplaced(String loginType, Object loginId, String tokenValue, String device) {
        log("被顶下线时触发:{},{},{},{}", loginType, loginId, tokenValue, device);
    }

    @Override
    public void doDisable(String loginType, Object loginId, long disableTime) {
        log("被封禁时触发:{},{},{}", loginType, loginId, disableTime);
    }

    @Override
    public void doUntieDisable(String loginType, Object loginId) {
        log("被解封时触发:{},{}", loginType, loginId);
    }

    @Override
    public void doCreateSession(String id) {
        log("创建Session时触发:{}", id);
    }

    @Override
    public void doLogoutSession(String id) {
        log("注销Session时触发:{}", id);
    }

    @Override
    public void findByUserInfo(String id) {
        log("查询用户信息:{}", id);
    }

    private void log(String s, Object... arguments) {
        if (log.isDebugEnabled()) {
            log.debug(s, arguments);
        }
    }
}
